<?php
    /**
     * Created by PhpStorm.
     * User: mybook-lhp
     * Date: 18/7/12
     * Time: 下午4:49
     */

    namespace app\payment\admin;


    use app\common\builder\ZBuilder;


    use app\payment\model\PaymentOrderModel;


    /**
     * 充值列表
     * Class Withdrawratio
     *
     * @package app\sharechain\admin
     */
    class Topup extends PaymentBase
    {

        public function index($status = null)
        {

            // 查询
            $map  = $this->getMap();
            $map_ = $map;
            if ($status !== null)
            {
                $map['payment_pay.status'] = $status;
            }
            if (isset($map['create_time']))
            {
                $map ["payment_pay.create_time"] = $map ["create_time"];
                unset ($map ["create_time"]);
            }
            if (isset($map['update_time']))
            {
                $map ["payment_pay.update_time"] = $map ["update_time"];
                unset ($map ["update_time"]);
            }

            // 排序
            $order = $this->getOrder('update_time desc');
            //检查权限
            $list_auth = check_auth_node(UID,'group',self::AUTH_GUADAN_WITHMONEY_LIST);


            // 数据列表

            $TopButtons = [];
            if ($list_auth)
            {

                $map['payment_pay.update_time'] = ['gt',strtotime(self::GROUP_TIEMS)];
                $map_['create_time']            = ['gt',strtotime(self::GROUP_TIEMS)];
            }
            $data_count = PaymentOrderModel::data_count($map_);
            $data_list  = PaymentOrderModel::getObjectData()->where($map)->order($order)->paginate();
            if (!$list_auth)
            {
                $TopButtons = [

                    'status0' => [
                        'class' => 'btn btn-danger',
                        'title' => '待支付：' . $data_count['status0'],
                        'href'  => url('index',['status' => 0])
                    ],
                    'status1' => [
                        'class' => 'btn btn-success',
                        'title' => '支付成功:' . $data_count['status1'],
                        'href'  => url('index',['status' => 1])
                    ],
                    'alipays' => [
                        'class' => 'btn btn-info',
                        'title' => '支付宝:' . $data_count['alipay'],
                        'href'  => url('index',['status' => 1])
                    ]
                ];
            }
            // 使用ZBuilder快速创建数据表格
            return ZBuilder::make('table')//
            ->addTimeFilter('create_time')// 添加时间段筛选
            ->addTopButton('back')//
            ->addColumns($this->addColumns_group($list_auth))//
            ->addTopButtons($TopButtons)// 批量添加顶部按钮

            ->addOrder('create_time')//排序
            ->setRowList($data_list)// 设置表格数据
            ->fetch(); // 渲染模板
        }

        /**
         * 数据展示
         *
         * @param bool $group
         *
         * @return array
         */
        public function addColumns_group($group = false)
        {

            if ($group)
            {
                $data = [ // 批量添加数据列
                          ['id','ID'],
                          ['order_sn','订单编号','text'],
                          //                          ['pay_sn','交易编号','text'],
                          //                          ['trade_sn','商户订单','text'],
                          ['phone','用户','text'],
                          ['type','支付方式','text','',[1 => '支付宝',2 => '微信',3 => '银行卡']],
                          ['money','充值金额','callback','view_money'],
                          ['status','状态','status','',[0 => '待支付',1 => '支付成功']],
                          //                             ['create_time','创建时间','datetime','','Y/m/d H:i:s'],
                          ['update_time','时间','datetime','','Y/m/d H:i:s'],
                ];
            }
            else
            {
                $data = [ // 批量添加数据列
                          ['id','ID'],
                          ['order_sn','订单编号','text'],
                          ['pay_sn','交易编号','text'],
                          ['trade_sn','商户订单','text'],
                          ['phone','用户','link',url('member/index/view',['id' => '__member_id__'])],
                          ['type','支付方式','text','',[1 => '支付宝',2 => '微信',3 => '银行卡']],
                          ['money','充值金额','callback','view_money'],
                          ['status','状态','status','',[0 => '待支付',1 => '支付成功']],
                          //                             ['create_time','创建时间','datetime','','Y/m/d H:i:s'],
                          ['update_time','时间','datetime','','Y/m/d H:i:s'],
                ];
            }
            return $data;
        }
    }